//
//  PBMyViewController.m
//  PBHomeDemo
//
//  Created by Playboy on 2017/11/21.
//  Copyright © 2017年 tmkj. All rights reserved.
//

#import "PBMyViewController.h"
#import "PBMyHeaderCell.h"
#import "PBMyListCell.h"
#import "PBMyInfoModel.h"
#import "PBChangeNickNameController.h"
#import "PBSuggestController.h"
#import "PBMyDeputeController.h"
#import "PBMyOrderController.h"

static NSString * const kPBMyHeaderCell = @"PBMyHeaderCell";
static NSString * const kPBMyListCell = @"PBMyListCell";


@interface PBMyViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (weak, nonatomic) IBOutlet UITableView *tableView;
@property (nonatomic, strong) PBMyInfoModel *model;

@end

@implementation PBMyViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view from its nib.
    [self configure];
}
- (void)viewWillAppear:(BOOL)animated {
    [super viewWillAppear:animated];
    [self configureData];
}
- (void)configure {
    [self configureView];
}
- (void)configureView {
    self.automaticallyAdjustsScrollViewInsets = NO;
    
    [self.tableView registerNib:[UINib nibWithNibName:kPBMyHeaderCell bundle:nil] forCellReuseIdentifier:kPBMyHeaderCell];
    [self.tableView registerNib:[UINib nibWithNibName:kPBMyListCell bundle:nil] forCellReuseIdentifier:kPBMyListCell];
    self.tableView.tableFooterView = [[UIView alloc] init];
}
- (void)configureData {
    NSDictionary *param = @{};
    [TMNetwork requestGetWithParam:param url:@"/user/getUserInfo" callback:^(TMBaseReqModel *model) {
        if (model.code == 200) {
            self.model = [PBMyInfoModel objectWithKeyValues:model.data];
            [self.tableView reloadRowsAtIndexPaths:@[[NSIndexPath indexPathForRow:0 inSection:0]] withRowAnimation:UITableViewRowAnimationNone];
        }else{
            self.model = nil;
            [self.tableView reloadData];
        }
    }];
}

#pragma mark - UITableViewDelegate,UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 1;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    PBMyHeaderCell *cell = [tableView dequeueReusableCellWithIdentifier:kPBMyHeaderCell forIndexPath:indexPath];
    cell.jumpVC = self;
    [cell refreshWithModel:self.model];
    return cell;
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath {
    return 590;
}

- (void)scrollViewDidScroll:(UIScrollView *)scrollView
{
    CGPoint point = scrollView.contentOffset;
    NSInteger yy;
    if (IS_IPHONE_X) {
        yy = 44;
    }else {
        yy = 22;
    }
    NSLog(@"%@",NSStringFromCGPoint(point));
    if (point.y < yy) {
        CGRect rect = [self.tableView viewWithTag:201].frame;
        rect.origin.y = point.y-yy;
        rect.size.height = -point.y + 243;
        [self.tableView viewWithTag:201].frame = rect;
    }
}


//// 我的预约
//- (void)enterMyDeputeVC {
//    PBMyDeputeController *vc = [[PBMyDeputeController alloc] init];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//}
//- (void)enterMyOrderVC {
//    PBMyOrderController *vc = [[PBMyOrderController alloc] init];
//    vc.hidesBottomBarWhenPushed = YES;
//    [self.navigationController pushViewController:vc animated:YES];
//}

#pragma mark - super
- (void)resetNavigationBarItems {
    self.title = @"我的";
}
- (void)resetNavigationBar {
    [self.navigationController setNavigationBarHidden:YES animated:YES];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
